package edu.cicese.alz.swing;

import javax.swing.JButton;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.Color;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 27/07/12
 * Time: 01:34 PM
 */
public class CustomButton extends JButton {
	private Color bgColor;
	private boolean pressed = false;
	private LineBorder pressedBorder = new LineBorder(SwingUtil.cPressedBorder);
	private LineBorder rolloverBorder = new LineBorder(SwingUtil.cRolloverBorder);

	public CustomButton(Color bgColor) {
		super();
		this.bgColor = bgColor;
		setBackground(bgColor);
	}


	public void paintSelected() {
		setBackground(SwingUtil.cPressed);
		setBorder(pressedBorder);
	}

	public void paintDeselected() {
		setBackground(bgColor);
		setBorder(new EmptyBorder(1, 1, 1, 1));
	}

	public void paintRollover() {
		setBackground(SwingUtil.cRollover);
		setBorder(rolloverBorder);
	}

	public void paintPressed() {
		setBorder(pressedBorder);
	}


	public void setEnabled(boolean enable) {
		super.setEnabled(enable);

		if (!enable) {
			paintDeselected();
		}
	}

	public void setBgColor(Color bgColor) {
		this.bgColor = bgColor;
	}

	public boolean isPressed() {
		return pressed;
	}

	public void setPressed(boolean pressed) {
		this.pressed = pressed;
	}
}